package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderManageService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "订单管理接口")
@Slf4j
@RequestMapping("/admin/order")
@RestController
public class OrderManageController {

    @Autowired
    private OrderManageService orderManageService;

    /**
     *各个状态的订单数量统计
     * @return
     */
    @ApiOperation("各个状态的订单数量统计")
    @GetMapping("/statistics")
    public Result orderCount(){

        OrderStatisticsVO result = orderManageService.orderCount();

        return Result.success(result);
    }

    /**
     * 查询订单详情
     * @return
     */
    @ApiOperation("查询订单详情")
    @GetMapping("/details/{id}")
    public Result orderDetails(@PathVariable Long id){

        OrderVO result = orderManageService.orderDetails(id);

        return Result.success(result);
    }
    /**
     * 订单搜索
     * @return
     */
    @ApiOperation("订单搜索")
    @GetMapping("/conditionSearch")
    public Result orderSearch(OrdersPageQueryDTO dto){
        PageResult pageResult = orderManageService.orderSearch(dto);
        return Result.success(pageResult);
    }
    /**
     * 派送订单
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result deliveryOrder (@PathVariable Long id) {
        log.info("派送订单:{}", id);
        orderManageService.deliveryOrder(id);
        return Result.success();
    }
    /**
     * 完成订单
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder (@PathVariable Long id) {
        log.info("完成订单:{}", id);
        orderManageService.completeOrder(id);
        return Result.success();
    }

    /**
     * 接收订单
     * @return
     */
    @ApiOperation("接收订单")
    @PutMapping("/confirm")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO dto){

        orderManageService.confirmOrder(dto);
        return Result.success();
    }

    /**
     * 取消订单
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO dto){

        orderManageService.cancelOrder(dto);

        return Result.success();
    }

    /**
     * 拒收订单
     * @return
     */
    @ApiOperation("拒收订单")
    @PutMapping("/rejection")
    public Result rejectOrder(@RequestBody OrdersRejectionDTO dto){

        orderManageService.rejectOrder(dto);

        return Result.success();
    }
}
